﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameworkManapro.BusinessModel;
using FrameworkManapro.WebUI;
using GMAC.ReportingSystem.Business.Entities;
using System.Collections;
using System.Data;

namespace GMAC.ReportingSystem.DataAccess
{
    public class StateDataAccess : BaseDataAccess<Business.Entities.State>
    {
        public override GMAC.ReportingSystem.Business.Entities.State Get(object id)
        {
            ArrayList parameters = new ArrayList() { id };
            DataTable dt = DataAccessComponent.ExecuteSelect("procStateByIdSelect", parameters);
            if (dt != null && dt.Rows.Count > 0)
                return ReadRow(dt.Rows[0]);
            return null;
        }

        public StateCollection GetList()
        {
            DataTable dt = DataAccessComponent.ExecuteSelect("procStateSelect", null);
            return ReadTable(dt) as StateCollection;
        }

        protected override GMAC.ReportingSystem.Business.Entities.State ReadRow(System.Data.DataRow row)
        {
            State State = null;
            if (row != null)
            {
                try
                {
                    State = new State();
                    State.Name = row["Name"].ToString();
                    State.ID = int.Parse(row["ID"].ToString());
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
            return State;
        }

        protected override List<GMAC.ReportingSystem.Business.Entities.State> ReadTable(System.Data.DataTable table)
        {
            try
            {
                StateCollection States = new StateCollection();
                State State;
                if (table != null && table.Rows.Count > 0)
                {
                    foreach (DataRow row in table.Rows)
                    {
                        State = ReadRow(row);
                        if (State != null)
                        {
                            States.Add(State);
                        }
                    }
                }
                return States;
            }
            catch (Exception ex)
            {
                throw;
            }
        }

     
    }
}

